home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
print
/
gsview10.zip
/
gsview.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-29
|
37KB
|
1,313 lines
/*
* gsview.c -- Main module of GSVIEW.EXE, a graphical interface for
* MS-Windows Ghostscript
* Copyright (C) 1993 Russell Lang
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Russell Lang
* Internet: rjl@monu1.cc.monash.edu.au
*/
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <commdlg.h>
#include <shellapi.h>
#include <mmsystem.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <dir.h>
#include <io.h>
#define NeedFunctionPrototypes 1
#include "ps.h"
#include "gsview.h"
char szAppName[MAXSTR]; /* application name - for title bar */
const char szClassName[] = "gsview_class";
const char szScratch[] = "gsview"; /* temporary filename prefix */
HWND hwndimg; /* gsview main window */
HWND hDlgModeless; /* any modeless dialog box */
HWND hwndtext; /* gswin text window */
HWND hwndimgchild; /* gswin image child window */
HINSTANCE phInstance; /* instance of gsview */
HINSTANCE gswin_hinst; /* instance of gswin */
int bitmap_scrollx=0; /* offset from bitmap to origin of child window */
int bitmap_scrolly=0;
int bitmap_width; /* size of gswin bitmap in pixels */
int bitmap_height;
/* these can be saved in the INI file */
char szGSwin[128]; /* command to invoke gswin */
POINT img_origin; /* gsview window origin */
POINT img_size; /* gsview window size */
BOOL quick; /* use quick opening (don't reload gswin) */
BOOL settings; /* save settings on exit */
BOOL button_show; /* show buttons bar */
int media; /* IDM_LETTER etc. */
char medianame[32]; /* name of media */
int user_width, user_height; /* User Defined media size */
BOOL epsf_clip; /* make bitmap size of epsf bounding box */
BOOL epsf_warn; /* write warning messages if operators incompatible with EPS are used */
BOOL redisplay; /* redisplay on resize */
BOOL safer; /* use -dSAFER option */
int orientation; /* IDM_PORTRAIT, IDM_LANDSCAPE etc. */
BOOL swap_landscape; /* swap IDM_LANDSCAPE & IDM_SEASCAPE */
float xdpi, ydpi; /* resolution of gswin bitmap */
UINT timeout; /* default timeout period in 1 sec units */
BOOL save_dir; /* remember current directory for next time */
char device_name[32]; /* printer name */
char device_resolution[32]; /* printer resolution */
struct sound_s sound[NUMSOUND] = {
{"SoundOutputPage", IDS_SNDPAGE, ""},
{"SoundNoPage", IDS_SNDNOPAGE, BEEP},
{"SoundNoNumbering", IDS_SNDNONUMBER, ""},
{"SoundNotOpen", IDS_SNDNOTOPEN, ""},
{"SoundError", IDS_SNDERROR, BEEP},
{"SoundTimeout", IDS_SNDTIMEOUT, ""},
{"SoundStart", IDS_SNDSTART, ""},
{"SoundExit", IDS_SNDEXIT, ""},
};
/* initialised in init.c */
BOOL is_win31 = FALSE; /* To allow selective use of win 3.1 features */
char szHelpName[MAXSTR]; /* buffer for building help filename */
char szHelpTopic[48]; /* topic for OFN_SHOWHELP */
UINT help_message; /* message sent by OFN_SHOWHELP */
HMENU hmenu; /* main menu */
HACCEL haccel; /* menu accelerators */
HCURSOR hcWait;
POINT img_offset; /* offset to gswin child window */
POINT info_file; /* position of file information */
POINT info_page; /* position of page information */
RECT info_rect; /* position and size of brief info area */
RECT info_coord; /* position and size of coordinate information */
RECT button_rect; /* position and size of button area */
BOOL prev_in_child; /* true if cursor previously in gswin child window */
BOOL waiting = FALSE; /* true when 'wait' to be displayed in info area */
BOOL page_ready = FALSE; /* true when gswin has sent an OUTPUT_PAGE and is waiting for NEXT_PAGE */
BOOL saved = FALSE; /* true if interpreter state currently saved in /gssave */
BOOL epsf_clipped; /* clipping this page? */
int page_skip = 5; /* number of pages to skip in IDM_NEXTSKIP or IDM_PREVSKIP */
int page_extra; /* extra pages to skip */
BOOL debug = FALSE; /* /D command line option used */
HINSTANCE hlib_mmsystem; /* DLL containing sndPlaySound function */
FPSPS lpfnSndPlaySound; /* pointer to sndPlaySound function if loaded */
/* timer used for open, close, display & print timeouts */
BOOL bTimeout; /* true if timeout occured */
BOOL bTimerSet; /* true if TIMER running */
#define ID_MYTIMER 1
UINT timeout_count;
/* document manipulation */
struct document *doc; /* DSC structure. NULL if not DSC */
int pagenum; /* current page number */
char dfname[MAXSTR]; /* name of selected document file */
char efname[MAXSTR]; /* name of temporary file containing PS extracted
from DOS EPS file */
FILE *dfile; /* selected file */
FILE *cfile; /* command file (pipe) */
BOOL is_ctrld; /* TRUE if DSC except for ctrl+D at start of file */
int preview; /* preview type IDS_EPSF, IDS_EPSI, etc. */
struct page_list_s page_list; /* page selection for print/extract */
/* local functions */
BOOL draw_button(DRAWITEMSTRUCT FAR *lpdis);
BOOL in_child_client_area(void);
BOOL in_client_area(void);
BOOL in_info_area(void);
void info_paint(HWND);
void gsview_close(void);
int gsview_command(WORD);
BOOL not_open(void);
BOOL not_dsc(void);
int PASCAL
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int cmdShow)
{
MSG msg;
/* copy the hInstance into a variable so it can be used */
phInstance = hInstance;
LoadString(hInstance, IDS_TITLE, szAppName, sizeof(szAppName));
if (hPrevInstance) {
/* don't run more than one copy */
/* because we can't run more than one Ghostscript */
gsview_init0(lpszCmdLine);
return FALSE;
}
gsview_init1(lpszCmdLine);
ShowWindow(hwndimg, cmdShow);
while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
if ((hDlgModeless == 0) || !IsDialogMessage(hDlgModeless, &msg)) {
if (!TranslateAccelerator(hwndimg, haccel, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
play_sound(SOUND_EXIT);
gsview_close();
WinHelp(hwndimg,szHelpName,HELP_QUIT,(DWORD)NULL);
if (is_win31 && (hlib_mmsystem != (HINSTANCE)NULL))
FreeLibrary(hlib_mmsystem);
return 0;
}
/* parent overlapped window */
LRESULT CALLBACK _export
WndImgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT rect;
if (message == WM_GSVIEW) {
switch(wParam) {
case HWND_TEXT:
/* lParam = handle to Ghostscript Borland EasyWin window */
hwndtext = (HWND)lParam;
break;
case HWND_IMGCHILD:
/* lParam = handle to Ghostscript image child window */
hwndimgchild = (HWND)lParam;
if (hwndimgchild && IsWindow(hwndimgchild)) {
SetClassCursor(hwndimgchild, LoadCursor((HINSTANCE)NULL, IDC_CROSS));
GetClientRect(hwnd, &rect);
SetWindowPos(hwndimgchild, (HWND)NULL, rect.left+img_offset.x, rect.top+img_offset.y,
rect.right-img_offset.x, rect.bottom-img_offset.y,
SWP_NOZORDER | SWP_NOACTIVATE);
}
break;
case GSWIN_CLOSE:
/* something is closing gswin */
gswin_hinst = (HINSTANCE)NULL;
hwndimgchild = (HWND)NULL;
hwndtext = (HWND)NULL;
bitmap_scrollx = bitmap_scrolly = 0;
page_ready = FALSE;
page_extra = 0;
saved = FALSE;
pipeclose();
clear_timer();
info_wait(FALSE);
break;
case OUTPUT_PAGE:
/* showpage has just been called */
clear_timer();
play_sound(SOUND_PAGE);
if (IsIconic(hwndimg)) /* useless as an Icon so fix it */
ShowWindow(hwndimg, SW_SHOWNORMAL);